import request from '@/utils/request'
import config from '../utils/config'
import store from '@/store'

export function downloadSchool (id, pdf) {
  if (pdf === true) {
    download(config.baseUrl + '/report/school?id=' + id + '&pdf=' + pdf)
  } else {
    download(config.baseUrl + '/report/school?id=' + id)
  }
}

export function downloadArea () {
  download(config.baseUrl + '/report/area?id=' + store.getters.areaId)
}

export function downloadCity () {
  download(config.baseUrl + '/report/city?id=' + store.getters.cityId)
}

export function downloadProvince () {
  download(config.baseUrl + '/report/province?id=' + store.getters.provinceId)
}

export function downloadSub (id) {
  download(config.baseUrl + '/report/sub?id=' + id)
}

function download (url) {
  setTimeout(function () {
    window.open(url)
  }, 100)
}

export function checkSchoolReport (id, pdf) {
  if (pdf === true) {
    return request({
      url: 'report/school/exist',
      params: {
        id: id,
        pdf: pdf
      },
      method: 'get'
    })
  } else {
    return request({
      url: 'report/school/exist',
      params: {
        id: id
      },
      method: 'get'
    })
  }
}

export function checkAreaReport () {
  return request({
    url: 'report/area/exist',
    params: {
      id: store.getters.areaId
    },
    method: 'get'
  })
}

export function checkCityReport () {
  return request({
    url: 'report/city/exist',
    params: {
      id: store.getters.cityId
    },
    method: 'get'
  })
}

export function checkProvinceReport () {
  return request({
    url: 'report/province/exist',
    params: {
      id: store.getters.provinceId
    },
    method: 'get'
  })
}

export function checkSubReport (id) {
  return request({
    url: 'report/sub/exist',
    params: {
      id: id
    },
    method: 'get'
  })
}
